package com.zxmclasslibrarie.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBHelper extends SQLiteOpenHelper {
    private static final String TAG = "SampleTest";
    private static final String db_name = "power_samples.db";

    private static final String sessions_table = "create table"
            + " sessions(_id integer primary key autoincrement,"
            + " start_time integer," + " start_average_v integer,"
            + " start_charge integer," + " stop_time integer,"
            + " stop_average_v integer," + " stop_charge integer,"
            + " stop_reason integer)";
    private static final String samples_table = "create table"
            + " samples(_id integer primary key autoincrement,"
            + " time integer," + " session_id integer)";
    private static final String alarm_table = "create table"
            + " alarm_samples(_id integer primary key autoincrement,"
            + " pkg integer," + " count integer," + " sample_id integer)";
    private static final String wakelock_table = "create table"
            + " wakelock_samples(_id integer primary key autoincrement,"
            + " tag txt," + " time_length integer," + " sample_id integer)";
    private static final String process_table = "create table"
            + " process_samples(_id integer primary key autoincrement,"
            + " pid integer," + " name text," + " rel_utime integer,"
            + " rel_stime integer," + " rel_uptime integer,"
            + " sample_id integer)";

    SQLiteDatabase db;

    public DBHelper(Context context) {
        super(context, db_name, null, 1);
        /*
         * if(db != null){ db.execSQL(sections_table);
         * db.execSQL(samples_table); db.execSQL(wakelocks_table); }
         */
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        this.db = db;
        db.execSQL(sessions_table);
        db.execSQL(samples_table);
        db.execSQL(alarm_table);
        db.execSQL(wakelock_table);
        db.execSQL(process_table);
        Log.d(TAG, "create tables ok");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
}
